package user.fragment;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

class OrderItem {
    private String orderId;
    private String orderNo;
    private int orderStatus;
    private String orderStatusString;
    private int totalPrice;
    private List<OrderGoodsItem> goodsItems = new ArrayList<>();

    public static OrderItem fromJson(JSONObject obj) {
        OrderItem item = new OrderItem();
        item.orderId = obj.optString("orderId");
        item.orderNo = obj.optString("orderNo");
        item.orderStatus = obj.optInt("orderStatus");
        item.orderStatusString = obj.optString("orderStatusString");
        item.totalPrice = obj.optInt("totalPrice");

        JSONArray goodsArray = obj.optJSONArray("newBeeMallOrderItemVOS");
        if (goodsArray != null) {
            for (int i = 0; i < goodsArray.length(); i++) {
                JSONObject goodsObj = goodsArray.optJSONObject(i);
                OrderGoodsItem goodsItem = new OrderGoodsItem();
                goodsItem.goodsCoverImg = goodsObj.optString("goodsCoverImg");
                goodsItem.goodsName = goodsObj.optString("goodsName");
                goodsItem.sellingPrice = goodsObj.optInt("sellingPrice");
                item.goodsItems.add(goodsItem);
            }
        }

        return item;
    }

    public String getOrderId() { return orderId; }
    public String getOrderNo() { return orderNo; }
    public int getOrderStatus() { return orderStatus; }
    public String getOrderStatusString() { return orderStatusString; }
    public int getTotalPrice() { return totalPrice; }
    public List<OrderGoodsItem> getGoodsItems() { return goodsItems; }

    public static class OrderGoodsItem {
        private String goodsCoverImg;
        private String goodsName;
        private int sellingPrice;

        public String getGoodsCoverImg() { return goodsCoverImg; }
        public String getGoodsName() { return goodsName; }
        public int getSellingPrice() { return sellingPrice; }
    }
}
